package com.yc.ui;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.wb.swt.SWTResourceManager;

import java.util.Map;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.widgets.Composite;

import com.yc.Idao.LoginIDao;
import com.yc.dao.LoginDao;
import com.yc.ui.dialog.MoneyDialog;
import com.yc.utils.ControlUtil;
import com.yc.utils.DataDict;
import com.yc.utils.SWTUtil;

import org.eclipse.swt.widgets.DateTime;

public class MainUI {

	protected Shell shell;
	protected Display display;
	public static Composite composite_1;
	
	protected static Map<String, Object> map;
	
	private static Label lblNewLabel_1;
	
	static String money;
	LoginIDao dao = new LoginDao();

	public MainUI(Map<String, Object> map) {
		this.map = map;
	}

	/**
	 * Launch the application.
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			MainUI window = new MainUI(null);
			window.open();			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Open the window.
	 */
	public void open() {
		display = Display.getDefault();
		createContents();
		shell.open();
		shell.layout();
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}

	/**
	 * Create contents of the window.
	 */
	protected void createContents() {
		shell = new Shell();
		shell.setSize(1087, 765);
		shell.setText("摸鱼客栈");
		shell.setLayout(new FillLayout(SWT.HORIZONTAL));
		
		shell.setImage(SWTResourceManager.getImage(MainUI.class, "/com/yc/images/小图标鱼.PNG"));
		
		
		SashForm sashForm = new SashForm(shell, SWT.VERTICAL);
		SWTUtil.centerWindow(shell);
		
		Composite composite = new Composite(sashForm, SWT.NONE);
		composite_1 = new Composite(sashForm, SWT.NONE);
		composite.setLayout(null);
		composite.setBackgroundImage( SWTResourceManager.getImage(MainUI.class, "/com/yc/images/主界面按钮框.PNG") );
		
		Button btnNewButton = new Button(composite, SWT.NONE);
		btnNewButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				MoneyDialog md = new MoneyDialog(shell, SWT.NONE, map.get("c_cardid").toString());
				md.open();
			}
		});
		btnNewButton.setImage(SWTResourceManager.getImage(MainUI.class, "/com/yc/images/充值按钮.png"));
		btnNewButton.setBounds(971, 25, 76, 30);
		btnNewButton.setText("充值");
		
		Button but = new Button(composite, SWT.NONE);
		but.setImage(SWTResourceManager.getImage(MainUI.class, "/com/yc/images/按钮.PNG"));
		but.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				composite.setBackgroundImage( SWTResourceManager.getImage(MainUI.class, "/com/yc/images/主界面按钮框.PNG") );
				SWTUtil.imagetSize(composite);
				but.setImage(SWTResourceManager.getImage(MainUI.class, "/com/yc/images/房间预约.png"));
				SWTUtil.imagetSize(but);
				btnNewButton.setImage(SWTResourceManager.getImage(MainUI.class, "/com/yc/images/充值按钮.png"));
				SWTUtil.imagetSize(btnNewButton);
				DataDict.stackLayout.topControl = DataDict.Room;//默认顶层显示
				composite_1.layout();//刷新
			}
		});
		but.setBounds(10, 10, 104, 104);
		but.setText("客房查询");
		ControlUtil.circleControl(but);
		
		Button but_1 = new Button(composite, SWT.NONE);
		but_1.setImage(SWTResourceManager.getImage(MainUI.class, "/com/yc/images/房间预约.png"));
		but_1.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				composite.setBackgroundImage( SWTResourceManager.getImage(MainUI.class, "/com/yc/images/主界面按钮框.PNG") );
				SWTUtil.imagetSize(composite);
				but_1.setImage(SWTResourceManager.getImage(MainUI.class, "/com/yc/images/房间预约.png"));
				SWTUtil.imagetSize(but_1);
				btnNewButton.setImage(SWTResourceManager.getImage(MainUI.class, "/com/yc/images/充值按钮.png"));
				SWTUtil.imagetSize(btnNewButton);
				DataDict.stackLayout.topControl = DataDict.Order;
				composite_1.layout();//刷新
				
			}
		});
		but_1.setText("预定房间");
		but_1.setBounds(121, 10, 104, 104);
		ControlUtil.circleControl(but_1);
		
		Button but_2 = new Button(composite, SWT.NONE);
		but_2.setImage(SWTResourceManager.getImage(MainUI.class, "/com/yc/images/登记入住.png"));
		but_2.setText("登记入住");
		but_2.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				composite.setBackgroundImage( SWTResourceManager.getImage(MainUI.class, "/com/yc/images/登记入住1.PNG") );
				SWTUtil.imagetSize(composite);
				btnNewButton.setImage(SWTResourceManager.getImage(MainUI.class, "/com/yc/images/登记入住界面充值.png"));
				SWTUtil.imagetSize(btnNewButton);
				DataDict.stackLayout.topControl = DataDict.Login;
				composite_1.layout();//刷新
			}
		});
		but_2.setBounds(232, 10, 104, 104);
		ControlUtil.circleControl(but_2);
		
		Button but_3 = new Button(composite, SWT.NONE);
		but_3.setImage(SWTResourceManager.getImage(MainUI.class, "/com/yc/images/餐饮管理.png"));
		but_3.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				composite.setBackgroundImage( SWTResourceManager.getImage(MainUI.class, "/com/yc/images/餐饮界面主界面1.PNG") );
				SWTUtil.imagetSize(composite);
				btnNewButton.setImage(SWTResourceManager.getImage(MainUI.class, "/com/yc/images/餐饮界面充值按钮.png"));
				SWTUtil.imagetSize(btnNewButton);
				if(dao.SelectLogin(map.get("c_cardid").toString()) != null) {
					DataDict.Goods = new Goods(composite_1, SWT.NONE);
				}
				DataDict.stackLayout.topControl = DataDict.Goods;
				composite_1.layout();//刷新
				
			}
		});
		but_3.setText("餐饮管理");
		but_3.setBounds(343, 10, 105, 105);
		ControlUtil.circleControl(but_3);
		
		Button but_4 = new Button(composite, SWT.NONE);
		but_4.setImage(SWTResourceManager.getImage(MainUI.class, "/com/yc/images/入住记录.png"));
		but_4.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				composite.setBackgroundImage( SWTResourceManager.getImage(MainUI.class, "/com/yc/images/消费记录界面1.PNG") );
				SWTUtil.imagetSize(composite);
				btnNewButton.setImage(SWTResourceManager.getImage(MainUI.class, "/com/yc/images/消费记录界面充值按钮.png"));
				SWTUtil.imagetSize(btnNewButton);
				DataDict.stackLayout.topControl = DataDict.LoginItem;
				composite_1.layout();//刷新
			}
		});
		but_4.setText("入住记录");
		but_4.setBounds(565, 10, 105, 105);
		ControlUtil.circleControl(but_4);
		
		Button but_6 = new Button(composite, SWT.NONE);
		but_6.setImage(SWTResourceManager.getImage(MainUI.class, "/com/yc/images/退房结账.png"));
		but_6.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				composite.setBackgroundImage( SWTResourceManager.getImage(MainUI.class, "/com/yc/images/退房结算界面主界面1.PNG") );
				SWTUtil.imagetSize(composite);
				btnNewButton.setImage(SWTResourceManager.getImage(MainUI.class, "/com/yc/images/退房结算界面主界面充值按钮.png"));
				SWTUtil.imagetSize(btnNewButton);
				if(dao.SelectLogin(map.get("c_cardid").toString()) != null) {
					DataDict.Check_out = new Check_out(composite_1, SWT.NONE, Login.l_id);
				}
				DataDict.stackLayout.topControl = DataDict.Check_out;
				composite_1.layout();//刷新
			}
		});
		but_6.setText("退房结算");
		but_6.setBounds(454, 10, 105, 105);
		ControlUtil.circleControl(but_6);
		
		DateTime dateTime = new DateTime(composite, SWT.BORDER);
		dateTime.setBounds(835, 74, 176, 40);
		
		Label lblNewLabel = new Label(composite, SWT.NONE);
		lblNewLabel.setBounds(787, 30, 76, 20);
		lblNewLabel.setText("账户余额：");
		
		lblNewLabel_1 = new Label(composite, SWT.NONE);
		lblNewLabel_1.setBounds(869, 30, 76, 20);
		getMoney();
		
		Button but_4_1 = new Button(composite, SWT.NONE);
		but_4_1.setImage(SWTResourceManager.getImage(MainUI.class, "/com/yc/images/历史评价按钮实现.png"));
		but_4_1.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				composite.setBackgroundImage( SWTResourceManager.getImage(MainUI.class, "/com/yc/images/退房结算界面主界面1.PNG") );
				SWTUtil.imagetSize(composite);
				btnNewButton.setImage(SWTResourceManager.getImage(MainUI.class, "/com/yc/images/历史评价按钮实现.png"));
				SWTUtil.imagetSize(btnNewButton);
				DataDict.Appraise = new Appraise(composite_1, SWT.NONE);
				DataDict.stackLayout.topControl = DataDict.Appraise;
				composite_1.layout();//刷新
				
			}
		});
		but_4_1.setBounds(676, 9, 105, 105);
		but_4_1.setText("历史评价");
		
		
		ControlUtil.circleControl(but_4_1);
		
		
		sashForm.setWeights(new int[] {1, 5});
		
		composite_1.setLayout(DataDict.stackLayout);//给右侧面板设置堆栈式布局
		//自定的层叠面板
		DataDict.Order = new Order(composite_1, SWT.NONE);
		DataDict.Room = new Room(composite_1, SWT.NONE, map);
		DataDict.Login = new Login(composite_1, SWT.NONE);
		
		DataDict.LoginItem = new LoginItem(composite_1, SWT.NONE);
	
		DataDict.stackLayout.topControl = DataDict.Room;//默认顶层显示
	}
	
	public static void getMoney() {
		LoginIDao dao = new LoginDao();
		money = dao.GetMoney(map.get("c_cardid").toString()).get("c_money").toString();
		lblNewLabel_1.setText(money);
	}
}
